package sg.edu.nus.iss.vmcs.store;

/**
 * Created by Phong on 10/6/2014.
 */
public class StoreIterator implements IStoreIterator<StoreItem> {
    private StoreItem[] collection;
    private int _current = -1;
    private int _step = 1;


    public StoreIterator(StoreItem[] collection){
        this.collection = collection;
    }

    @Override
    public StoreItem next() {
        _current+=_step;
        return current();
    }

    @Override
    public StoreItem prev() {
        _current-=_step;
        return current();
    }

    @Override
    public StoreItem current() {
        return collection[_current];
    }

    @Override
    public int currentIndex() {
        return _current;
    }

    @Override
    public boolean hasNext() {
        return _current < collection.length - 1;
    }

    @Override
    public boolean hasPrev() {
        return _current > 0;
    }

    @Override
    public void prepareReverse() {
        _current = collection.length;
    }
}
